<template>
    <div class="wrapper">
      <div class="head">
        <div class="title">
          {{title}}
        </div>
        <div class="like" v-if="showLike">
          <transition name = "el-zoom-in-center">
            <i @click="toLike" v-show = "show" :class="like"></i>
          </transition>
        </div>
      </div>
      <div id="content">
        <dl v-html="content">
          {{content}}
        </dl>
      </div>
    </div>
</template>

<script>
export default {
  props: ['login'],
  name: 'newsDetail',
  data () {
    return {
      like: 'el-icon-star-off',
      title: '',
      content: '',
      showLike: false,
      show: true
    }
  },
  methods: {
    toLike () {
      this.http.get(this.ports.news.detail + '/' + this.$route.query.id + '/likeControl',
        res => {
          if (res.status === 200) {
            let data = res.data.result
            if (data.code === 200) {
              this.show = !this.show
              if (data.Like === true) {
                setTimeout(() => {
                  this.like = 'el-icon-star-on'
                  this.show = !this.show
                }, 500)
              } else if (data.Like === false) {
                setTimeout(() => {
                  this.like = 'el-icon-star-off'
                  this.show = !this.show
                }, 500)
              }
            } else if (data.code === 1 || data.code === -1) {
              console.log(data)
            }
          } else if (res.status === 401) {
            this.$emit('toLog', 'true')
          } else {
            console.log(res)
          }
        })
    }
  },
  mounted: function () {
    this.http.get(this.ports.news.detail + '/' + this.$route.query.id,
      res => {
        if (res.status === 200) {
          let data = res.data.result
          if (data.code === 200) {
            this.title = data.title
            this.content = data.content
            this.showLike = data.showLike
            if (data.showLike && data.hasLike) {
              this.like = 'el-icon-star-on'
            }
          } else if (data.code === 1 || data.code === -1) {
            console.log(data)
          }
        } else if (res.status === 401) {

        } else {
          console.log(res)
        }
      })
  }
}
</script>

<style lang='scss' scoped>
  .wrapper {
    margin: auto;
    width: 60%;
    padding-top: 1rem;
  }
  .head {
    height: 100px;
    line-height: 100px;
    font-size: 0.5rem;
    display: flex;
    justify-content: space-between;
    font-weight: 800;
  }
  .like {
    font-size: 30px;
  }
  .like :hover{
    opacity: 0.7;
  }
  .content {
    height: 500px;
    margin-bottom: 1rem;
    overflow: hidden;
  }
  .like /deep/ .el-icon-star-on {
    color: rgba(253,192,47,1);
    cursor: pointer;
  }
  .like /deep/ .el-icon-star-off {
    color: rgba(253,192,47,1);
    cursor: pointer;
  }
  #content {
    padding: 30px 0 100px 0;
  }
  /* table 样式 */
  #content /deep/ table {
    border-top: 1px solid #ccc;
    border-left: 1px solid #ccc;
  }
  #content /deep/ table td,
  #content /deep/ table th {
    border-bottom: 1px solid #ccc;
    border-right: 1px solid #ccc;
    padding: 3px 5px;
  }
  #content /deep/ table th {
    border-bottom: 2px solid #ccc;
    text-align: center;
  }
  /* blockquote 样式 */
  #content /deep/ blockquote {
    display: block;
    border-left: 8px solid #d0e5f2 !important;
    padding: 5px 10px;
    margin: 10px 0;
    line-height: 1.4;
    font-size: 100%;
    background-color: #f1f1f1;
  }
  /* code 样式 */
  #content /deep/ code {
    display: inline-block;
    *display: inline;
    *zoom: 1;
    background-color: #f1f1f1;
    border-radius: 3px;
    padding: 3px 5px;
    margin: 0 3px;
  }
  #content /deep/ pre code {
    display: block;
  }
  /* ul ol 样式 */
  #content /deep/ ul, ol {
    margin: 10px 0 10px 20px;
  }
  #content /deep/ div p span{
    line-height: 30px;
  }
</style>
